<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <h:head>
        <title>#{bundle_items_vi.Title}</title>
        <script>
            function confirmComplete() {
                var answer = confirm("Bạn có chắc chắn muốn xóa bản ghi này?");
                if (answer == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        </script>
        <style type="text/css">
            .ui-inputfield{                
                width: 100%;
            }
        </style>
    </h:head>
    <h:body> 
        <link type="text/css" rel="stylesheet" href="../css/main.css" />        
        <style type="text/css">
            .ui-widget{font-size:95% !important;}
            .ui-layout-unit-content{background-color: #E5E5E5;border-width: 0px}      
            .ui-widget{border-width: 0px;color: red}
        </style>
        <div align="center" id="bodyForm" >
            <div style="width: 100%;">
                <p:layoutUnit id="top" position="north" size="auto">
                    <ui:insert name="menu">
                        <ui:include src="../../templates/menu.xhtml"/>
                    </ui:insert>
                </p:layoutUnit>
                <p:layoutUnit id="center" position="center" size="400">
                    <h1 class="headerbar">#{bundle_items_vi.Title}</h1>
                    <p:outputPanel id="pnP" style="width: 100%;">
                        <p:growl id="message"/>
                        <p:panel>
                            <h:form id="form" style="width: 100%;">
                                <p:dialog modal="true" widgetVar="statusDialog" header="#{bundle_items_vi.Searching}"   
                                          draggable="false" closable="false">  
                                    <p:graphicImage value="../../images/ajax-loader.gif" />  
                                </p:dialog>
                                <div align="center" style="margin-top: 10px;margin-bottom: 10px;margin-left: 10px;">
                                    <h:panelGrid columns="4">
                                        <p:selectOneMenu value="#{itemsController.typeS}" >
                                            <f:selectItem itemValue="0" itemLabel="#{bundle_items_vi.Name}: "/>
                                            <f:selectItem itemValue="1" itemLabel="#{bundle_items_vi.CategoryName}: "/>
                                            <f:selectItem itemValue="2" itemLabel="#{bundle_items_vi.PublisherName}: "/>
                                            <f:selectItem itemValue="3" itemLabel="#{bundle_items_vi.MediaType}: "/>
                                            <p:ajax event="change" update=":pnP"/>
                                        </p:selectOneMenu>
                                        <p:inputText value="#{itemsController.inputS}"/><p:commandButton icon="ui-icon ui-icon-search" value="#{bundle_items_vi.Search}" action="#{itemsController.search()}" update=":pnP" onclick="statusDialog.show();" oncomplete="statusDialog.hide();"/>
                                        <p:commandButton value="#{bundle_items_vi.Add}" onclick="dlgAdd.show()" icon="ui-icon ui-icon-plusthick" update=":formAdd" actionListener="#{itemsController.updateAdd()}"/>
                                    </h:panelGrid>
                                </div>
                            </h:form>
                        </p:panel>
                        <p:panel>
                            <h:form style="width: 100%" id="form2">
                                <p:panel header="#{bundle_items_vi.HeaderItems}" id="pnltree">
                                    <p:dataTable id="tbItems" 
                                                 var="item" 
                                                 value="#{itemsController.list}"
                                                 rowKey="#{item.id}"                                                                                                 
                                                 style="width: 100%;" paginator="true" rows="20"
                                                 rowsPerPageTemplate="20,25,30">
                                        <p:column headerText="#{bundle_items_vi.ItemId}">
                                            <h:outputText value="#{item.id}" style="float: right;"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_items_vi.Name}">
                                            <p:commandLink onclick="dlgEdit.show()" update=":formEdit" actionListener="#{itemsController.updateEdit()}" value="#{item.name}" style="float: right;">
                                            </p:commandLink>
                                        </p:column>

                                        <p:column headerText="#{bundle_items_vi.CategoryName}">
                                            <h:outputText value="#{item.categoryName}" style="float: right;"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_items_vi.PublisherName}">
                                            <h:outputText value="#{item.publisherName}" style="float: right;"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_items_vi.ViewCount}">
                                            <h:outputText value="#{item.viewCount}" style="float: right;"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_items_vi.DownloadCount}">
                                            <h:outputText value="#{item.downloadCount}" style="float: right;"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_items_vi.MediaType}">
                                            <h:outputText value="#{item.mediaType}" style="float: right;"/>
                                        </p:column>
                                        
                                        <p:column headerText="#{bundle_items_vi.Content_type}">
                                            <h:outputText value="#{item.content_type}" style="float: right;"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_items_vi.Edit}" style="width: 10px">
                                            <div align="center">
                                                <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-pencil" onclick="dlgEdit.show()" update=":formEdit" actionListener="#{itemsController.updateEdit()}"/>
                                            </div>
                                        </p:column>
                                        <p:column headerText="#{bundle_items_vi.Delete}" style="width: 10px">                                            
                                            <div align="center">
                                                <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-trash" onclick="return confirmComplete()" update=":pnP" action="#{itemsController.remove()}"/>
                                            </div>
                                        </p:column>
                                    </p:dataTable>                                    
                                </p:panel>
                            </h:form>   
                        </p:panel>
                        <!--dialog them add-->
                        <p:dialog modal="true" widgetVar="dlgAdd" header="#{bundle_items_vi.HeaderDlgAdd}" resizable="false">
                            <p:scrollPanel style="width: 800px;height: 600px" mode="native">
                                <h:form style="width: 100%;height: 100%;" id="formAdd">
                                    <p:growl id="message1"/>
                                    <h:panelGrid columns="1" style="width: 100%;">
                                        <p:panel header="#{bundle_items_vi.Item}">
                                            <h:panelGrid columns="2">                                                                                        
                                                <h:outputText value="#{bundle_items_vi.MediaType}: "/> 
                                                <p:selectOneMenu value="#{itemsController.ctId}" style="width: 165px">
                                                    <f:selectItems value="#{itemsController.listContTem}" var="ct" itemLabel="#{ct.name}" itemValue="#{ct.id}"/>
                                                    <p:ajax event="change" update=":formAdd" listener="#{itemsController.updateProperty()}"/>
                                                </p:selectOneMenu>                                                
                                                <h:outputText value="#{bundle_items_vi.CategoryName}: "/> 
                                                <p:selectOneMenu value="#{itemsController.cateId}" style="width: 165px">
                                                    <f:selectItems value="#{itemsController.listCate}" var="c" itemLabel="#{c.name}" itemValue="#{c.id}"/>                                                     
                                                </p:selectOneMenu>
                                                <h:outputText value="#{bundle_items_vi.PublisherName}: "/> 
                                                <p:selectOneMenu value="#{itemsController.pubId}" style="width: 165px">
                                                    <f:selectItems value="#{itemsController.listPub}" var="p" itemLabel="#{p.name}" itemValue="#{p.id}"/>
                                                </p:selectOneMenu>
                                                
                                                <h:outputText value="#{bundle_items_vi.Content_type}: "/> 
                                                <p:selectOneMenu value="#{itemsController.currentItem.content_type}" style="width: 165px">
                                                    <f:selectItem itemLabel="bin" itemValue="bin"/>
                                                    <f:selectItem itemLabel="text" itemValue="text"/>
                                                </p:selectOneMenu>  
                                                
                                                <h:outputText value="#{bundle_items_vi.Name}: "/> <p:inputText value="#{itemsController.currentItem.name}"/>
                                                <h:outputText value=""/>
                                                <h:panelGrid columns="2">
                                                    <p:commandButton value="#{bundle_items_vi.Save}" style="width: 60px" action="#{itemsController.insert()}" update=":pnP"/>
                                                    <p:commandButton value="Thêm nhiều" style="width: 100px" update=":frmAddNhiu" onclick="dlgAddNhiu.show()" actionListener="#{itemsController.updateAddNhiu()}"/>
                                                </h:panelGrid>
                                            </h:panelGrid>                                                                                        
                                        </p:panel>
                                        <p:panel header="#{bundle_items_vi.Property}">                                        
                                            <p:dataTable value="#{itemsController.listProperty}" var="p">                                            
                                                <p:column  style="width: 15%">
                                                    <h:outputText value="#{p.propertyName}: " style="float: left;"/>
                                                </p:column>
                                                <p:column>
                                                    <p:inputTextarea cols="100" rows="2" value="#{p.id}" style="float: right;font-size: 20px;"/>
                                                </p:column>
                                            </p:dataTable>
                                        </p:panel>
                                    </h:panelGrid>
                                </h:form>
                            </p:scrollPanel>
                        </p:dialog>
                        <!--dialog add nhiều-->
                        <p:dialog modal="true" widgetVar="dlgAddNhiu" header="Thêm nhiều" resizable="false">
                            <h:form id="frmAddNhiu">
                                <p:growl id="msgAddNhiu"/>                                
                                <p:fileUpload fileUploadListener="#{itemsController.upload}"
                                              allowTypes="/(\.|\/)(xlsx)$/" sizeLimit="10000000" description="Select Images" update=":frmAddNhiu"/> 
                                <h:panelGrid rendered="#{itemsController.checkDLExcell}" columns="2">
                                    <h:outputText value="Những lỗi xảy ra!"/>
                                    <p:commandButton id="downloadLink" value="Download" ajax="true" onclick="PrimeFaces.monitorDownload(start, stop)"   
                                                     icon="ui-icon ui-icon-arrowthick-1-s">  
                                        <p:fileDownload value="#{itemsController.fileEr}" />  
                                    </p:commandButton> 
                                </h:panelGrid>
                            </h:form>
                        </p:dialog>
                        <!--dialog edit-->
                        <p:dialog modal="true" widgetVar="dlgEdit" header="#{bundle_items_vi.HeaderDlgEdit}" resizable="false">
                            <p:scrollPanel style="width: 800px;height: 600px" mode="native">
                                <h:form style="width: 100%;height: 100%;" id="formEdit">
                                    <p:growl id="message1"/>
                                    <h:panelGrid columns="1" style="width: 100%;">
                                        <p:panel header="#{bundle_items_vi.Item}">
                                            <h:panelGrid columns="2">
                                                <h:outputText value="Id: " style="display: none;"/> <p:inputText value="#{itemsController.currentItem.id}" style="display: none;"/>
                                                <h:outputText value="#{bundle_items_vi.Name}: "/> <p:inputText value="#{itemsController.currentItem.name}" style="width: 150px"/>                                        
                                                <h:outputText value="#{bundle_items_vi.CategoryName}: "/> 
                                                <p:selectOneMenu value="#{itemsController.cateId}" style="width: 150px">
                                                    <f:selectItems value="#{itemsController.listCate}" var="c" itemLabel="#{c.name}" itemValue="#{c.id}"/>
                                                </p:selectOneMenu>
                                                <h:outputText value="#{bundle_items_vi.PublisherName}: "/>
                                                <p:selectOneMenu value="#{itemsController.pubId}" style="width: 150px">
                                                    <f:selectItems value="#{itemsController.listPub}" var="p" itemLabel="#{p.name}" itemValue="#{p.id}"/>
                                                </p:selectOneMenu>
                                                <h:outputText value="#{bundle_items_vi.Content_type}: "/> 
                                                <p:selectOneMenu value="#{itemsController.currentItem.content_type}" style="width: 150px">
                                                    <f:selectItem itemLabel="bin" itemValue="bin"/>
                                                    <f:selectItem itemLabel="text" itemValue="text"/>
                                                </p:selectOneMenu>                                                
                                                <h:outputText value="#{bundle_items_vi.MediaType}: " style="display: none;"/> 
                                                <p:selectOneMenu value="#{itemsController.ctId}" style="width: 150px;display: none" >
                                                    <f:selectItems value="#{itemsController.listContTem}" var="ct" itemLabel="#{ct.name}" itemValue="#{ct.id}"/>
                                                    <p:ajax event="change" update=":formEdit" listener="#{itemsController.updatePropertyEdit()}"/>
                                                </p:selectOneMenu>
                                                <h:outputText value=""/>
                                                <h:panelGrid columns="2">
                                                    <p:commandButton value="#{bundle_items_vi.Save}" style="width: 60px" action="#{itemsController.update()}" update=":pnP"/>
                                                </h:panelGrid>
                                            </h:panelGrid>
                                        </p:panel>
                                        <p:panel header="#{bundle_items_vi.Property}">                                        
                                            <p:dataTable value="#{itemsController.listProperty}" var="p">                                            
                                                <p:column style="width: 15%">
                                                    <h:outputText value="#{p.propertyName}: " style="float: left;"/>
                                                </p:column>
                                                <p:column>
                                                    <p:inputTextarea cols="100" rows="2" value="#{p.id}" style="float: right;font-size: 20px;"/>
                                                </p:column>
                                            </p:dataTable>
                                        </p:panel>
                                    </h:panelGrid>
                                </h:form>
                            </p:scrollPanel>
                        </p:dialog>
                    </p:outputPanel>
                </p:layoutUnit>
                <p:layoutUnit id="bottom" position="bottom" size="60">
                    <ui:insert name="footer">
                        <ui:include src="../../templates/footer.xhtml"/>
                    </ui:insert>
                </p:layoutUnit>
            </div>
        </div>
    </h:body>
</html>

